package com.example.fresh_fruit.service.Impl;

import com.example.fresh_fruit.entity.Head;
import com.example.fresh_fruit.mapper.HeadMapper;
import com.example.fresh_fruit.service.HeadService;
import com.example.fresh_fruit.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :飞天の鱼
 * @date : 2022/8/17 15:50
 */
@Service
public class HeadServiceImpl implements HeadService {

    @Autowired
    private HeadMapper headMapper;


    @Override
    public int checkHead(Integer id) {
        Head head = headMapper.findById(id);
        if (head==null){
            Result.fail("无此团长");
            return 1;
        }else{
            Integer headState=head.getState();
            if (headState!=0){
                Result.fail("团长不干了");
                return 2;
            }
        }
        Result.ok("一切正常");
        //团长状态正常
        return 0;
    }

    @Override
    public boolean insert(Head head) {
        return headMapper.insert(head);
    }

    @Override
    public boolean delete(Integer id,Integer state) {
        return headMapper.delete(id,state);
    }

    @Override
    public boolean update(Head head) {
        return false;
    }

    @Override
    public Head findById(Integer id) {
        return headMapper.findById(id);
    }

    @Override
    public List<Head> selectAll() {
        return headMapper.selectAll();
    }

    @Override
    public boolean insertFace(Head head) {
        return headMapper.insertFace(head);
    }

    @Override
    public boolean upBanlance(Head head) {
        return headMapper.upBanlance(head);
    }
}
